package com.xuecheng.basic.controller;

import com.xuecheng.basic.domain.Dictionary;
import com.xuecheng.commons.model.vo.DictionaryVo;
import com.xuecheng.commons.model.vo.ResponseResult;
import com.xuecheng.commons.utils.BeanHelper;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xuecheng.basic.service.DictionaryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * <p>
 * 数据字典前端控制器
 * </p>
 *
 * @author itheima
 */
@Slf4j
@RestController
@RequestMapping("/dictionary")
public class DictionaryController {

    @Autowired
    private DictionaryService  dictionaryService;

    //查询所有的数据字典
    @GetMapping
    public ResponseResult findAll(){
        //调用service查询所有
        List<Dictionary> list = dictionaryService.list();
        //进行对象转化
        List<DictionaryVo> vos = BeanHelper.copyWithCollection(list, DictionaryVo.class);
        //返回
        return ResponseResult.okResult(vos);
    }

    //根据code查询数据字典
    @GetMapping("/{code}")
    public ResponseResult findByCode(@PathVariable("code") String code){
        return dictionaryService.findByCode(code);
    }
}
